package com.gaogzhen.juc.visibility.volatileTest;

import java.util.concurrent.TimeUnit;

public class Test05 {
    static int x;

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            while (true) {
                if (Thread.currentThread().isInterrupted()){
                    System.out.println(x);
                    break;
                }
            }
        }, "t1");
        t1.start();

        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            x = 10;
            t1.interrupt();
        }, "t2").start();

        while (!t1.isInterrupted()) {
            Thread.yield();
        }
        System.out.println(x);
    }
}
